package SortCode;

/**
 * Created by kechelle on 2020/8/13 12:35
 * 冒泡排序
 */
public class code2 {
    //从小到大
    public static void BubbleSort1(int[] nums){
        for (int i=0;i<nums.length;i++){
            for (int j=0;j< nums.length-i-1;j++){
                if (nums[j]>nums[j+1]){
                    int temp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = temp;
                }
            }
        }
    }

    //从大到小
    public static void BubbleSort2(int[] nums){
        for (int i=nums.length-1;i>0;i--){
            for (int j=nums.length-1;j> nums.length-i-1;j--){
                if (nums[j]>nums[j-1]){
                    int temp = nums[j];
                    nums[j] = nums[j-1];
                    nums[j-1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {72,6,57,88,60,42,83,73,48,85};
        BubbleSort2(nums);
        for (int num:nums){
            System.out.print(num + " ");
        }
    }
}
